'use strict';

import React from 'react';
import {
    NativeModules,
} from 'react-native';

export const configkey = {
    LoginState: "loginstate",
    UserId: "userguid",
    UserPwd: "userpwd",
    UserToken: "token",
    ShopKey: "spk",
    ShopId: "shopId",
    Mobile: "mobile",
    UserName: "username",
    UserSex: "usersex",
    UserBirth: "userbirth",
    UserHead: "userhead",
    CurrentPlace: "currentplace",
    CurrentPlaceCode: "currentplacecode",
    HistoryCitys: "historycity",
    ShopToken: "shoptoken",
    ShopAddress: "shopaddress",
    ShopLogo: "shoplogo",
    ShopName: "shopname"
};

export const navi = (isneedLogin,router,params) => {
    NativeModules.RNJsBridge.invoke("navi",{router:router,isneedLogin:isneedLogin,params:params},() =>{

    });
}

export const getConfig = (keys, callback) => {
    NativeModules.RNJsBridge.invoke("getconfigvalue", {keys: keys}, (params) => {
        callback(params);
    });
};

//图片上传
export const chooseImage = (params, callback) => {
    NativeModules.RNJsBridge.invoke("photoUtils", params, (res) => {
        callback(res);
    })
};

export const chooseLocation = (params, callback) => {
    NativeModules.RNJsBridge.invoke('chooseMapLocation', params, (res) => {
        callback(res);
    })
};

export const editRichContent = (params, callback) => {
    NativeModules.RNJsBridge.invoke('editRichContent', params, (res) => {
        callback(res);
    })
};

export const showLoading = (value) => {
    NativeModules.RNJsBridge.invoke('showloading', {info: value}, (res) => {
    })
}

export const hideLoading = (value) => {
    NativeModules.RNJsBridge.invoke('hideloading', {}, (res) => {
    })
}

export const toast = (value) => {
    NativeModules.RNJsBridge.invoke('showinfo', {info: value}, (res) => {
    });
};

export const getGoodsCategory = (params, callback) => {
    NativeModules.RNJsBridge.invoke('getGoodsCategory', params, (res) => {
        callback(res);
    })
}

export const setConfigValue = (key, value) => {
    NativeModules.RNJsBridge.invoke("setconfigvalue", {key: key, value: value}, (res) => {
    })
};

export const getGoodsAttrRelations = (catcode, callback) => {
    NativeModules.RNJsBridge.invoke("getgoodsattrrelation", {catcode: catcode}, (res) => {
        callback(res);
    })
};


export const LoginOutPlugin = (success) => {
    NativeModules.RNJsBridge.invoke("logout", {}, (res) => {
        success();
    })
};


/**
 * 选择区域
 * @param success
 * @constructor
 */
export const ChooseCity = (success) => {
    NativeModules.RNJsBridge.invoke("chooseCity", {}, (res) => {
        success(res);
    });
};

/**
 * 根据dicid 取值
 */
export const GetValuesByDicId = (dicid, callback) => {
    NativeModules.RNJsBridge.invoke("getitemvalue", {dicid: dicid}, (res) => {
        callback(res);
    })
};




